package edu.scut.autoProcessor.dao;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;

import edu.scut.autoProcessor.po.AlertPo;

public class AlertDao extends AbstractDao{

	private static final Log logger = LogFactory.getLog(AlertDao.class);
	
	private static final int PAGE_LENGTH = 15;
	
	public static void insertAlert(AlertPo po){
		SqlSession sqlSession = factory.openSession();
		
		try{
			sqlSession.insert("alertProcessor.alertMapper.insertAlert", po);
		}catch(Exception e){
			logger.warn(e.getMessage());
			e.printStackTrace();
		}finally{
			sqlSession.close();
		}
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<AlertPo> queryAlert(Map parameters, int page){
		SqlSession sqlSession = factory.openSession();
		
		try{
			int offset = (page - 1) * PAGE_LENGTH;
		
			parameters.put("offset", offset);
			parameters.put("pageLength", PAGE_LENGTH);
		
			return sqlSession.selectList("alertProcessor.alertMapper.selectAlert", parameters);
		}catch(Exception e){
			logger.error(e.getMessage());
			e.printStackTrace();
			return null;
		}finally{
			sqlSession.close();
		}
	}
	
}
